﻿#include "joincompanywidget.h"
#include "ui_joincompanywidget.h"
#include <QDebug>

JoinCompanyWidget::JoinCompanyWidget(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::JoinCompanyWidget)
{
    ui->setupUi(this);

    setWindowTitle("加入企业");
    ui->pushButtonJoin->setEnabled(false);

    connect(&companyService, &CompanyService::queryCompanySuccess,
            [=](Company &company)
    {
        ui->lineEditCompanyName->setText(company.companyName);
        ui->lineEditContact->setText(company.contact);
        ui->lineEditTel->setText(company.tel);
        ui->lineEditFax->setText(company.fax);
        ui->lineEditWebsite->setText(company.website);
        ui->lineEditEmail->setText(company.email);
        ui->textEditIntroduction->setText(company.introduction);

        ui->pushButtonJoin->setEnabled(true);
    });

    connect(&companyService, &CompanyService::joinCompanySuccess,
            [=]()
    {
        this->close();
        emit joinCompanySuccess();
    });
}

JoinCompanyWidget::~JoinCompanyWidget()
{
    delete ui;
}

void JoinCompanyWidget::showAndClear()
{
    ui->lineEditCompanyId->setText("");
    ui->lineEditCompanyName->setText("");
    ui->lineEditContact->setText("");
    ui->lineEditTel->setText("");
    ui->lineEditFax->setText("");
    ui->lineEditWebsite->setText("");
    ui->lineEditEmail->setText("");
    ui->textEditIntroduction->setText("");
    ui->pushButtonJoin->setEnabled(false);
    exec();
}

void JoinCompanyWidget::on_pushButtonCancel_clicked()
{
    this->close();
}

void JoinCompanyWidget::on_pushButtonQuery_clicked()
{
    companyService.queryCompany(this, ui->lineEditCompanyId->text());
}

void JoinCompanyWidget::on_pushButtonJoin_clicked()
{
    companyService.joinCompany(this, ui->lineEditCompanyId->text());
}
